package com.lin.manager.controller.system;

import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.resp.R;
import com.lin.manager.system.service.SysAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作者: 林江
 * @创建时间: 2024-03-13 14:37:36
 * @功能:
 */
@Api(tags = "地域管理")
@RestController
@RequestMapping("area")
public class SysAreaController {

    @Autowired
    SysAreaService sysAreaService;

    @ApiOperation("地域管理 - 根据条件获取地域树形")
    @Log(module = "地域管理", descipt = "根据条件获取地域树形", type = LogEnum.SELECT)
    @GetMapping("listTree/{level}")
    public R listTree(String name, @PathVariable("level") Integer level) {
        return R.ok(sysAreaService.listTree(name, level));
    }

    @ApiOperation("地域管理 - 添加地域")
    @Log(module = "地域管理", descipt = "添加地域", type = LogEnum.INSERT)
    @GetMapping("add")
    public R add(String name) {
        Assert.notNull(name, "添加的地域名称不能为空");
        sysAreaService.add(name);
        return R.ok();
    }

}
